const path = require('path');
const w = require('webpack');
const p = require('purifycss-webpack');
const g = require('glob-all');
const ext = require('extract-text-webpack-plugin'); // purifycss需要分离出去的否则没用

module.exports = {
    entry: {
        idx: './src/idx.js'
    },
    output: {
	filename: '[name].[chunkHash].js',
	path: path.resolve(__dirname, './dist/'),
    },
    module: {
        rules:[
	    {
		test: /\.css$/,
		use: ext.extract({
                     
                    fallback: {
                        loader: 'style-loader'
                    },

                     
                    use:[{
                        loader:'css-loader'
                    }]
                })


	    },
	    {
		test: /\.js$/,
		use: [{
		    loader: 'babel-loader',
		    options:{
			presets: ['env'],
			plugins: ['lodash']
		   }
		}]
	    }
	]
    },
    plugins:[
        new ext({
            filename: '[name].m.css',
         }),
        // purify-css 一定放在这个之前
	new p({
	    paths: g.sync([
		path.join(__dirname, './index.html'),
		path.join(__dirname, './src/**/*.js'),
			
	    ])
	}),
	new w.optimize.UglifyJsPlugin()
    ]
}
